<!DOCTYPE html>
<html lang="zh-cn" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
<title th:text="|#{customer.systemTitle}-图灵谷-全局配置-全局配置|">图灵谷</title>
<div th:replace="fragments/head_admin">head</div>
</head>
<body>
	<div class="layui-layout layui-layout-admin">
		<div th:replace="fragments/nav_admin">导航栏</div>
		<div th:replace="fragments/menu_admin::menu(parent=gconfig,child=model)">菜单栏</div>
		<div class="layui-body">
			<div class="layui-main">
				<!--/***** 面包屑 *****/-->
				<div class="layui-elem-quote" style="margin-top: 10px;">
					<span class="layui-breadcrumb"> <a><cite>全局配置</cite></a> <a th:href="@{/admin/m/base/model/list.gsp}">模型配置</a> <a><cite>列表</cite></a>
					</span>
				</div>
				<blockquote class="layui-elem-quote layui-quote-nm" style="color: #FF5722">
					<i class="layui-icon">&#xe60b;</i>字段管理
				</blockquote>
				<input name="ownerType" th:value="|${result.type}Model|" type="hidden" /> <input name="ownerId" th:value="${result.id}" type="hidden" />
				<blockquote class="layui-elem-quote layui-quote-nm">
					<div class="layui-inline">
						<div class="layui-input-inline">
							<a th:href="@{/admin/m/base/customField/add.gsp}" class="layui-btn"><i class="layui-icon">&#xe608;</i> 新增</a>
						</div>
					</div>
				</blockquote>

				<div class="layui-form-item">
					<div class="layui-inline" style="width: 45%;">
						<fieldset class="layui-elem-field layui-field-title">
							<legend>已存在字段</legend>
						</fieldset>
						<table id="cusTable" class="layui-table" lay-even="" lay-skin="row">
							<thead>
								<tr>
									<th>字段名称</th>
									<th>字段标签</th>
									<th>字段类型</th>
									<th style="width: 90px;">操作</th>
								</tr>
							</thead>
							<tbody>
								<tr th:if="${cusList == null or cusList.size() == 0}">
									<td colspan="4" style="text-align: center;">暂时没有数据</td>
								</tr>
								<tr th:each="item,itemStat:${cusList}">
									<td name="fieldName" th:text="${item.fieldName}" style="text-align: center;"></td>
									<td th:text="${item.fieldLabel}" style="text-align: center;"></td>
									<td style="text-align: center;"><label th:if="${item.type==1}">文本输入框</label> <label th:if="${item.type==2}">日期输入框</label> <label th:if="${item.type==3}">单选框</label> <label th:if="${item.type==4}">多选框</label> <label th:if="${item.type==5}">文本域</label> <label th:if="${item.type==6}">文本编辑器</label>
										<label th:if="${item.type==7}">图片上传</label> <label th:if="${item.type==8}">图片集上传</label> <label th:if="${item.type==9}">视频上传</label> <label th:if="${item.type==10}">附件上传</label> <label th:if="${item.type==11}">文库上传</label> <label th:if="${item.type==12}">属性控件</label></td>
									<td><a th:href="|@{/admin/m/base/customField/edit_}${item.id}.gsp|" class="layui-btn layui-btn-small"> <i class="layui-icon"></i></a><a th:onclick="|del('${item.id}')|" class="layui-btn layui-btn-normal layui-btn-small"> <i class="layui-icon"></i></a></td>
								</tr>
							</tbody>
						</table>
					</div>
					<div class="layui-inline" style="width: 45%;">
						<fieldset class="layui-elem-field layui-field-title">
							<legend>可添加字段</legend>
						</fieldset>
						<table id="sysTable" class="layui-table" lay-even="" lay-skin="row">
							<thead>
								<tr>
									<th style="width: 40px;">操作</th>
									<th>字段名称</th>
									<th>字段标签</th>
									<th>字段类型</th>
								</tr>
							</thead>
							<tbody>
								<tr th:if="${sysList == null or sysList.size() == 0}">
									<td colspan="4" style="text-align: center;">暂时没有数据</td>
								</tr>
								<tr th:each="item,itemStat:${sysList}">
									<td><a class="layui-btn layui-btn-small layui-btn-danger" th:onclick="|addSysField('${item.fieldName}')|"><i class="layui-icon">&#xe603;</i></a>
									<td name="fieldName" th:text="${item.fieldName}" style="text-align: center;"></td>
									<td th:text="${item.fieldLabel}" style="text-align: center;"></td>
									<td style="text-align: center;"><label th:if="${item.type==1}">文本输入框</label> <label th:if="${item.type==2}">日期输入框</label> <label th:if="${item.type==3}">单选框</label> <label th:if="${item.type==4}">多选框</label> <label th:if="${item.type==5}">文本域</label> <label th:if="${item.type==6}">文本编辑器</label>
										<label th:if="${item.type==7}">图片上传</label> <label th:if="${item.type==8}">图片集上传</label> <label th:if="${item.type==9}">视频上传</label> <label th:if="${item.type==10}">附件上传</label> <label th:if="${item.type==11}">文库上传</label> <label th:if="${item.type==12}">属性控件</label></td>
								</tr>
							</tbody>
						</table>
					</div>
				</div>
			</div>
		</div>
		<div th:replace="fragments/footer_admin">底部</div>
	</div>
</body>
<div th:replace="fragments/import_js_admin">引入js</div>
</html>
<script th:inline="javascript">
    /*<![CDATA[*/ 
    //替换fieldName
    //var cusList = /*[[${cusList}]]*/;
    /*for(i=0;i<cusList.length;i++){
        var type = cusList[i].type;
        var str = "";
        if (type == 1 || type == 3 || type == 4 || type == 5 || type == 7 || type == 8 || type == 9 || type == 10 || type == 11) {
            str = "cus_str_";
        } else if (type == 2) {
            str = "cus_date_";
        } else {
            str = "cus_blob_";
        }  
    }
    var fieldNameVal = $('#cusTable td[name="fieldName"]').val().replace(str, "");
    $('#cusTable td[name="fieldName"]').val(fieldNameVal);
    fieldNameVal = $('#cusTable td[name="fieldName"]').val().replace(str, ""); */
    //将右侧添加到左侧
    function addSysField(fieldName) {
        var url = /*[[@{/admin/m/base/customField/addSysField.gsp}]]*/'url';
        var parms = {
            fieldName : fieldName,
            ownerType : /*[[|${result.type}Model|]]*/'ownerType',
            ownerId : /*[[${result.id}]]*/'ownerId'
        }
        $.post(url,parms,function(data){
            var result = $.parseJSON(data);
            if(result.success==false){
                layer.alert(result.msg);
            }else{
                setTimeout(function(){
                    location.reload(); 
                },100);
            }
            
        });
        /* tg_simpleAjaxPost(url, parms, function() {
            location.reload(); 
        }); */
    }
    
    var deleteUrl = /*[[@{/admin/m/base/customField/delete_{id}.gsp}]]*/;
    function del(id){
        tg_deleteItem(deleteUrl.replace('{id}',id), function(){           
            location.reload();
        });       
    }
    /*]]>*/
</script>